package thread;

import java.util.concurrent.*;

/**
 * created by lanwp on 2019/2/26.
 */
public class CallableDemo implements Callable<String> {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        /*Thread t = new Thread(() -> {

        });*/
        ExecutorService service = Executors.newCachedThreadPool();
        Future<String> future = service.submit(() -> {
            TimeUnit.SECONDS.sleep(2);
            return "123";
        });

        System.out.println("....");
        System.out.println(future.get());
        System.out.println("子线程操作完成....");
        System.out.println(future.get());

    }

    @Override
    public String call() throws Exception {
        return name;
    }
}
